<?php
include( "admin/now5_header.php" );
$sql = "select * from bet where bettype=27 and lotto_id=" . $lotto_id . " and rame in (0,9)";
$percent = 0;
$betcount = array();
$lostwin = array();
$totalamount = array();
$betids = array(2, 3, 4, 5);
$ary = array();
foreach ($betids as $betid)
{
    $totalamount[$betid] = 0;
    $betcount[$betid] = 0;
    $ary[$betid] = array();
    $i = 0;
    while ($i < 50)
    {
        $ary[$betid][$i] = array("num" => "", "amount" => 0);
        $lostwin[$betid][$i] = 0;
        ++$i;
    }
}
$sql .= " order by amount desc, numbers";
$rs = getdb($sql);

while (!$rs->eof)
{
    $percent = $rs->f['upercent'];
    if (0 < $percent)
    {
        $percent /= 100;
    }
    $p = explode("|", $rs->f['numbers']);
    $type = $p[0];
    $num = $p[1];
    $tmp = $percent * $rs->f['amount'];
    $n = Scan_LM_Array($type, $num, $ary, 50);
    if ($n < 0)
    {
        $j = Empty_LM_Array($type, $ary, 50);
        if (0 <= $j)
        {
            $ary[$type][$j]['num'] = $num;
            $ary[$type][$j]['amount'] = $tmp;
        }
    }
    else
    {
        $ary[$type][$n] += "amount";
    }
    ++$betcount[$type];
    $totalamount[$type] ++;
    $rs->movenext();
}

$rs->close();
$sql = "select * from bet2 where lotto_id=" . $lotto_id . " and bettype=27 and rame in (0,9)";
$rs = getdb($sql);
while (!$rs->eof)
{
    $backs = $rs->f['back5'];
    $percent = $rs->f['percent255'];
    if (0 < $percent)
    {
        $percent /= 100;
    }
    $p = explode("|", $rs->f['numbers']);
    $type = $p[0];
    $num = $p[1];
    $tmp = $percent * $rs->f['amount'];
    $n = Scan_LM_Array($type, $num, $ary, 50);
	
    if ($n < 0)
    {
        $j = Empty_LM_Array($type, $ary, 50);
        if (0 <= $j)
        {
            $ary[$type][$j]['num'] = $num;
            $ary[$type][$j]['amount'] = $tmp;
        }
    }
    else
    {
        
	$ary[$type][$n] ++;
		
    }
    ++$betcount[$type];
    $totalamount[$type] ++;
    $rs->movenext();
}

$rs->close();
$sql = "select * from bet8 where lotto_id=" . $lotto_id . " and bettype=27 and rame in (0,9)";
$rs = getdb($sql);
while (!$rs->eof)
{
    $p = explode("|", $rs->f['numbers']);
    $type = $p[0];
    $num = $p[1];
    $tmp = $rs->f['amount'];
    $n = Scan_LM_Array($type, $num, $ary, 50);
    if ($n < 0)
    {
        $j = Empty_LM_Array($type, $ary, 50);
        if (0 <= $j)
        {
            $ary[$type][$j]['num'] = $num;
            $ary[$type][$j]['amount'] = 0 - $tmp;
        }
    }
    else
    {
        $ary[$type][$n] -= "amount";
    }
    ++$betcount[$type];
    $totalamount[$type] --;
    $rs->movenext();
}
$rs->close();
$list2 = "";
if (0 < $betcount[2])
{
    $i = 0;
    while ($i < 50)
    {
        $lostwin[2][$i] = 0 - $ary[2][$i]['amount'];
        ++$i;
    }
    asort($lostwin[2]);
    reset($lostwin[2]);
    $i = 0;
    foreach ($lostwin[2] as $key => $val)
    {
        if ($i < 30)
        {
            $c = $ary[2][$key]['num'];
            $n = $ary[2][$key]['amount'];
            if ($c != "")
            {
                $list2 .= "<tr align=center>";
                $list2 .= "<td nowrap><a href=" . get_listurl6($open, 2, $c) . ">" . show_linechinayear($c) . "</a></td>";
                $list2 .= "<td nowrap align=right><font color=#0000A8><b>" . $n . "</b></font></td></tr>";
                ++$i;
            }
        }
    }
}
$list3 = "";
if (0 < $betcount[3])
{
    $i = 0;
    while ($i < 50)
    {
        $lostwin[3][$i] = 0 - $ary[3][$i]['amount'];
        ++$i;
    }
    asort($lostwin[3]);
    reset($lostwin[3]);
    $i = 0;
    foreach ($lostwin[3] as $key => $val)
    {
        if ($i < 30)
        {
            $c = $ary[3][$key]['num'];
            $n = $ary[3][$key]['amount'];
            if ($c != "")
            {
                $list3 .= "<tr align=center>";
                $list3 .= "<td nowrap><a href=" . get_listurl6($open, 3, $c) . ">" . show_linechinayear($c) . "</a></td>";
                $list3 .= "<td nowrap align=right><font color=#0000A8><b>" . $n . "</b></font></td></tr>";
                ++$i;
            }
        }
    }
}
$list4 = "";
if (0 < $betcount[4])
{
    $i = 0;
    while ($i < 50)
    {
        $lostwin[4][$i] = 0 - $ary[4][$i]['amount'];
        ++$i;
    }
    asort($lostwin[4]);
    reset($lostwin[4]);
    $i = 0;
    foreach ($lostwin[4] as $key => $val)
    {
        if ($i < 30)
        {
            $c = $ary[4][$key]['num'];
            $n = $ary[4][$key]['amount'];
            if ($c != "")
            {
                $list4 .= "<tr align=center>";
                $list4 .= "<td nowrap><a href=" . get_listurl6($open, 4, $c) . ">" . show_linechinayear($c) . "</a></td>";
                $list4 .= "<td nowrap align=right><font color=#0000A8><b>" . $n . "</b></font></td></tr>";
                ++$i;
            }
        }
    }
}
$list5 = "";
if (0 < $betcount[5])
{
    $i = 0;
    while ($i < 50)
    {
        $lostwin[5][$i] = 0 - $ary[5][$i]['amount'];
        ++$i;
    }
    asort($lostwin[5]);
    reset($lostwin[5]);
    $i = 0;
    foreach ($lostwin[5] as $key => $val)
    {
        if ($i < 30)
        {
            $c = $ary[5][$key]['num'];
            $n = $ary[5][$key]['amount'];
            if ($c != "")
            {
                $list5 .= "<tr align=center>";
                $list5 .= "<td nowrap><a href=" . get_listurl6($open, 5, $c) . ">" . show_linechinayear($c) . "</a></td>";
                $list5 .= "<td nowrap align=right><font color=#0000A8><b>" . $n . "</b></font></td></tr>";
                ++$i;
            }
        }
    }
}
$tpl->set("money2", $totalamount[2]);
$tpl->set("money3", $totalamount[3]);
$tpl->set("money4", $totalamount[4]);
$tpl->set("money5", $totalamount[5]);
$tpl->set("list2", $list2);
$tpl->set("list3", $list3);
$tpl->set("list4", $list4);
$tpl->set("list5", $list5);
$rs = getdb("select * from rate27 where lotto_id=" . $lotto_id . " LIMIT 1");
if ($rs->eof)
{
    $ui->showErrorPage("<p class=error>系统目前维护中，请稍後！</p>");
    exit();
}
$tpl->load("main", "now6.htm");
$tpl->set("jslang", $g_conf['language']);
$tpl->show("main");
$ui->footer();
?>